/*YfzoVe7IaIrWbjv+q6Uv3gBkubNmYOmfcAmAS8NT3NwQN6SJoGVL4uzgl1fw+9UP*/
/*
 * @Descripttion: 主页面页签表格按钮点击事件
 * @version:
 * @Author: Chendch
 * @Date: 2020-11-26 11:24:46
 * @LastEditors: Chendch
 * @LastEditTime: 2021-05-19 13:30:53
*/
import {ajax, toast} from "nc-lightapp-front";
import {Urls} from "../../CONSTANCE";
import { deleteFinanceOrStock } from './SupCardButtonAction';
import { getDialogConfig, showAddressBookDialog} from '../../../utils/SupplierUtils';
export default function(key,flag,text,record,index) {
    switch(flag){
        case 'edit':
            if(key == 'purchase' || key == 'finance') {
                const meta = this.props.meta.getMeta();
                meta["supfinance_card"].items.find(i=>{
                    //专管部门选完 给专管业务员参照左树设置过滤条件
                    if(i.attrcode == 'pk_resppsn' || i.attrcode == 'respperson'){
                        i.queryCondition = {
                            pk_org: record.values.pk_org.value
                        }
                    }
                    if(i.attrcode == 'pk_respdept' ){
                        i.queryCondition = {
                            pk_org: record.values.pk_org.value
                        }
                    }

                });
                this.props.meta.setMeta(meta);
                this.onRowDoubleClick(key,'edit',record, index, this.props);
            }else {
                expandLinkManModal.call(this, key,flag,record);
            }
            break;
        case 'delete':
            if(key =='purchase' || key == 'finance'){
                this.setState({
                    dblClkRecord:record
                },()=>{
                    deleteFinanceOrStock.call(this,false,key);
                    //onFinanceOrStockDelete.call(this,false,key);
                });
            }else{
                this.props.editTable.deleteTableRowsByIndex(key,index);
            }
            break;
        case 'address':
            this.setState({openDialog:true},()=>{
                showAddressBookDialog.call(this,record.values['pk_supplier'].value,{pk_supstock:record.values['pk_supstock'].value,baseInfoAddress:false,orgId:record.values['pk_org'].value});
            })
            break;
        case 'assign':
            if(key == 'suplinkman'){

                if(!!record.values['pk_linkman.cell'].value && record.values['pk_linkman.cell'].value.trim()!=''){
                    this.assignOrg(record.values['pk_linkman.cell'].value);
                }else{
                    toast({ content: this.Lang['10140SUG-000229'], color: 'danger' });
                }

            }
            break;
        default:
            expandLinkManModal.call(this, key,flag,record);
            break;
    }
}

function expandLinkManModal(key,flag,record) {
    if(key == "suplinkman") {
        this.setState({openDialog:true},()=>{
            ajax({
                url:Urls.queryLinkmanUrl,
                data:{pk_linkman:record.values['pk_linkman'].value,nodeType:this.props.nodeType,pk_curOrg:this.state.envParam.pk_org},
                success:(res)=>{
                    if(res.success){
                        let linkManParam = {disAssign: this.state.disAssign}
                        this.Dialog.showDialog(Object.assign(getDialogConfig.call(this,'LinkmanDialog', linkManParam),{Lang:this.Lang}),()=>{
                            this.props.form.setAllFormValue({linkman:res.data['linkman']});
                            this.props.form.setFormStatus('linkman', flag == "browse" ? "browse" : "edit"); //设置表单编辑态
                        });
                    }
                }
            });
            //查询组织！
            ajax({
                url: '/nccloud/baseapp/mobile/orgsgrid.do',
                data: {
                    phone: record.values['pk_linkman.cell'].value,
                    type: 2
                },
                async: false,
                success: (res) => {
                    const {success,data} = res;
                    if(!success) return ;
                    this.props.table.setAllTableData("SubjectOrg", data ? data.SubjectOrg : {rows: []});
                },
                error: (msg) => {
                    toast({ content: msg.message, color: 'danger' });
                }
            });
        })
    }
}
/*YfzoVe7IaIrWbjv+q6Uv3gBkubNmYOmfcAmAS8NT3NwQN6SJoGVL4uzgl1fw+9UP*/
